BETWEEN.PRG stores the cross-section specific means of each series in a matrix, creates a new workfile, converts the matrix to series, and runs the between groups regression.
' between group esitmation for pool' revised for version 5.0 (3/25/2004) 'change path to data path%path = @runpathcd %path ' load workfileload pool1 ' define poolsmpl @allpool pool1.add aut bus con cst dep hoa mae mis ' set number of cross-sections!ncross = pool1.@ncross ' create group with variablespool1.makegroup(tempgrp) log(ivm?) log(mm?) ' store means of two series in matrixmatrix(!ncross,2) meansseries tempserfor !i = 1 to !ncross tempser = tempgrp(!i) means(!i,1) = @mean(tempser) tempser = tempgrp(!ncross+!i) means(!i,2) = @mean(tempser)nextstore(i) meansdelete tempgrp tempser ' create new workfile and fetch means matrixwfcreate between u 1 !ncrossfetch(i) means ' convert matrix to seriesseries lc_meanseries ly_meangroup g1 lc_mean ly_meanmtos(means,g1) ' run between groups regression and cleanupequation eq_bet.ls lc_mean c ly_meanshow eq_bet
HAUSMAN.PRG computes the Hausman test statistic for testing the null hypothesis that the fixed and random effects models do not differ systematically. The program estimates a fixed and random effects model with two slope regressors and stores the estimated coefficients and its covariance matrix. (The version of the Grunfeld data used in this example is transcribed from Greene (1997), Table 15.1.).
' hausman test for fixed versus random effects' revised for version 6.0 (3/6/2007) 'change path to program path %path = @runpath cd %path ' load workfileload grunfeld ' set samplesmpl @first 1947 ' estimate fixed effects and store resultspool1.ls(cx=f) log(inv?) log(val?) log(cap?)vector beta = pool1.@coefsmatrix covar = pool1.@cov ' keep only slope coefficientsvector b_fixed = @subextract(beta,1,1,2,1)matrix cov_fixed = @subextract(covar,1,1,2,2) ' estimate random effects and store resultspool1.ls(cx=r) log(inv?) log(val?) log(cap?)beta = pool1.@coefscovar = pool1.@cov ' keep only slope coefficientsvector b_gls = @subextract(beta,2,1,3,1)matrix cov_gls = @subextract(covar,2,2,3,3) ' compute Hausman test statmatrix b_diff = b_fixed - b_glsmatrix var_diff = cov_fixed - cov_glsmatrix qform = @transpose(b_diff)*@inverse(var_diff)*b_diff if qform(1,1)>=0 then ' set table to store results table(4,2) result setcolwidth(result,1,20) setcell(result,1,1,"Hausman test for fixed versus random effects") setline(result,2) !df = @rows(b_diff) setcell(result,3,1,"chi-sqr(" + @str(!df) + ") = ") setcell(result,3,2,qform(1,1)) setcell(result,4,1,"p-value = ") setcell(result,4,2,1-@cchisq(qform(1,1),!df)) setline(result,5) show resultelse statusline "Quadratic form is negative"endif